import express from 'express'
var router = express.Router();
import formatTime  from '../../../util/formatTime.js'

import {getResult, listSql, countSql}  from '../../../util/operateSql.js'

const table = 'spider.sina_siper_news'

router.get('/list', (req,res, next) => {
  const params = req.query
  const sql = listSql(table,{...req.query,orderBy:'post_hot',orderBy: 'update_time'},'like')  
  let rows = getResult(sql)
  rows.then(async (result) => {
    const sql = countSql(table,{...req.query,orderBy:'post_hot'},'like')
    const count = await getResult(sql)
    res.json(req.app.locals.success({list:result,total:count[0].count}))
  }).catch((err) => {
    res.json(req.app.locals.error(err))
  });
})

export default router;
